/*
 * Copyright 2022 Haulmont.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.jmix.flowui.data.items;

import com.vaadin.flow.data.provider.ListDataProvider;

import java.util.Arrays;

/**
 * A data provider that uses an enumeration type as its data source.
 *
 * @param <T> the type of the enumeration items provided by this data provider
 */
public class EnumDataProvider<T> extends ListDataProvider<T> {

    protected final Class<T> enumClass;

    public EnumDataProvider(Class<T> enumClass) {
        super(Arrays.asList(enumClass.getEnumConstants()));
        this.enumClass = enumClass;
    }

    /**
     * Returns the enumeration class used as the data source.
     *
     * @return the class of the enumeration used by this data provider
     */
    public Class<T> getEnumClass() {
        return enumClass;
    }
}
